#!/bin/bash
source openrc.sh
# database
mysql -uroot -p$DB_PASS -e "create database IF NOT EXISTS keystone ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY '$KEYSTONE_DBPASS' ;"
mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY '$KEYSTONE_DBPASS' ;"
yum install -y openstack-keystone httpd mod_wsgi
crudini --set  /etc/keystone/keystone.conf database connection mysql+pymysql://keystone:$KEYSTONE_DBPASS@$CONTROLLER_HOST_NAME/keystone
crudini --set  /etc/keystone/keystone.conf token provider fernet
su -s /bin/sh -c "keystone-manage db_sync" keystone
# Install and configure components
keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
keystone-manage bootstrap --bootstrap-password $ADMIN_PASS \
  --bootstrap-admin-url http://$CONTROLLER_HOST_NAME:5000/v3/ \
  --bootstrap-internal-url http://$CONTROLLER_HOST_NAME:5000/v3/ \
  --bootstrap-public-url http://$CONTROLLER_HOST_NAME:5000/v3/ \
  --bootstrap-region-id RegionOne
echo "ServerName $CONTROLLER_HOST_NAME" >> /etc/httpd/conf/httpd.conf
ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
systemctl enable httpd.service
systemctl start httpd.service
cat >> /etc/my.cnf.d/openstack.cnf << EOF
EOF
# env script
cat >> /etc/admin-openrc << EOF
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=$ADMIN_PASS
export OS_AUTH_URL=http://$CONTROLLER_HOST_NAME:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
EOF
#Create a domain, projects, users, and roles
source /etc/admin-openrc
openstack project create --domain default --description "Service Project" service
openstack token issue
